home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / PlayerPRO 4.5.8 / PlayerPRO 4.5.8 Dev.Kit / MADH Library 4.5 / MacOS Examples / Game.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-10  |  3.1 KB  |  133 lines  |  [TEXT/CWIE]

  1. /********************************************************/
  2. /*
  3.     Player PRO 4.5 -- Music Driver EXAMPLE
  4.     
  5.     To use with MusicLibrary 4.x for Think C & CodeWarrior
  6.  
  7.     Antoine ROSSET
  8.     16 Tranchees
  9.     1206 GENEVA
  10.     SWITZERLAND
  11.     
  12.     FAX: (+41 22) 346 11 97
  13.     PHONE: (+41 79) 203 74 62
  14.     Email: rosset@dial.eunet.ch
  15. */
  16. /********************************************************/
  17.  
  18. #include "RDriver.h"
  19.  
  20. /*****************************/
  21. /****** MAIN FUNCTION ********/
  22. /*****************************/
  23.  
  24. void main( void)
  25. {
  26. DialogPtr        TheDia;
  27. Handle            itemHandle;
  28. Rect            itemRect;
  29. short            itemType, i, itemHit;
  30. Handle            mySound[ 4];            // my 4 sound resource
  31.  
  32. /* Initialisation de la toolbox */
  33.  
  34. InitGraf( &qd.thePort);
  35. InitFonts();
  36. InitWindows();
  37. TEInit();
  38. InitMenus();
  39. InitCursor();
  40. MaxApplZone();
  41.  
  42. /******************************************/
  43. /*** Load and prepare my sound resource ***/
  44. /******************************************/
  45.  
  46. for( i = 0 ; i < 4; i++)
  47. {
  48.     mySound[ i] = GetResource( 'snd ', 128 + i);
  49.     DetachResource( mySound[ i]);
  50.     HLock( mySound[ i]);                            // VERY IMPORTANT !!!!!!
  51. }
  52.  
  53.  
  54. /*******************************************************************************************/
  55. /****** MAD Library Initialisation : choose the best driver for the current hardware  ******/
  56. /*******************************************************************************************/
  57.  
  58. {
  59.     MADDriverSettings    init;
  60.     OSErr                err;
  61.     
  62.     err = MADInitLibrary("", false);
  63.     if( err) DebugStr("\pMADInitLibrary Err");
  64.     
  65.     MADGetBestDriver( &init);
  66.     
  67.     err = MADCreateDriver( &init);
  68.     if( err) DebugStr("\pMADCreateDriver Err");
  69. }
  70.  
  71. /***************************************************/
  72. /***   Open MADH Resource ID 3214 and play it !   **/
  73. /***************************************************/
  74.  
  75. if( MADLoadMusicRsrc( 'MADH', 3214) != noErr) DebugStr("\pMADLoadMusicRsrc Err");
  76. if( MADStartDriver() != noErr) DebugStr("\pMADStartDriver Err");
  77.  
  78. /******************************************/
  79. /***        Open my dialog              ***/
  80. /******************************************/
  81.  
  82. TheDia = GetNewDialog( 128,0L, (WindowPtr) -1L);
  83. SetPort( TheDia);        
  84.  
  85. do
  86. {
  87.     ModalDialog( 0L, &itemHit);
  88.         
  89.     switch( itemHit)
  90.     {
  91.         case 2:
  92.             GetDialogItem( TheDia, 2, &itemType, &itemHandle, &itemRect);
  93.             SetControlValue( (ControlHandle) itemHandle, !GetControlValue( (ControlHandle) itemHandle));
  94.             
  95.             if( GetControlValue( (ControlHandle) itemHandle)) MADPlayMusic();
  96.             else MADStopMusic();
  97.         break;
  98.     
  99.         case 3:
  100.             MADPlaySndHandle( mySound[ 0], 0, 48);            // On track ID 0, C 3 = 48
  101.         break;
  102.         
  103.         case 4:
  104.             MADPlaySndHandle( mySound[ 1], 1, 0xFF);        // On track ID 0, 0xFF = normal rate (sample rate)
  105.         break;
  106.         
  107.         case 5:
  108.             MADPlaySndHandle( mySound[ 2], 2, 36);            // On track ID 1, at C 2 = 36
  109.         break;
  110.         
  111.         case 6:
  112.             MADPlaySndHandle( mySound[ 3], 3, 60);            // On track ID 2, at C 4 = 60
  113.         break;
  114.     }
  115.     
  116. }while( itemHit != 1);
  117.  
  118. DisposeDialog( TheDia);
  119.  
  120. MADStopMusic();                        // Stop the music
  121. MADStopDriver();                    // Stop the driver
  122. MADDisposeMusic();                    // Clear music
  123. MADDisposeDriver();                    // Dispose driver
  124. MADDisposeLibrary();                // Close Music Library
  125.  
  126. for( i = 0 ; i < 4; i++)
  127. {
  128.     HUnlock( mySound[ i]);
  129.     DisposeHandle( mySound[ i]);
  130. }
  131. }
  132.  
  133.